package com.recharge.controller.callback;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.recharge.OrderService;
import com.recharge.domain.TradeFlow;
import com.recharge.domain.TradeOrder;
import com.recharge.mapper.ITradeFlowMapper;
import com.recharge.mapper.ITradeOrderMapper;
import com.recharge.sup.AbsSupChargeService;


@Controller
@RequestMapping("/wangchi")
public class WangChiCallBackController {
    private Logger logger = LoggerFactory.getLogger(getClass());

    @Autowired
    private ITradeOrderMapper iTradeOrderMapper;

    @Autowired
    private ITradeFlowMapper iTradeFlowMapper;

    @Autowired
    private OrderService orderService;

    @Resource(name = "wangChiChargeServiceImpl")
    private AbsSupChargeService absSupChargeService;

    @RequestMapping("/callback")
    @ResponseBody
    public String wangChi(@RequestParam("orderid")String orderid,
                              @RequestParam("userid")String userid,
                              @RequestParam("bizid")String bizid,
                              @RequestParam("mobile")String mobile,
                              @RequestParam("resultCode")String resultCode,
                              @RequestParam("resultMsg")String resultMsg,
                              @RequestParam("key")String key){
        Map<String, String> paramMap = new HashMap<String, String>();
        paramMap.put("orderid", orderid);
        paramMap.put("userid", userid);
        paramMap.put("bizid", bizid);
        paramMap.put("mobile", mobile);
        paramMap.put("resultCode", resultCode);
        paramMap.put("resultMsg", resultMsg);
        paramMap.put("key", key);
        
        logger.info("orderID:{},收到结果回调,返回信息code:{}",orderid,resultMsg);
        
        TradeOrder tradeOrder =iTradeOrderMapper.selectByOrderId(bizid);
        TradeFlow tradeFlow = iTradeFlowMapper.selectByOrderId((short) 2, bizid);
        absSupChargeService.response(tradeOrder,tradeFlow,paramMap);

        return "1";
    }
}
